package com.kun.admin.authority.controller;

import com.kun.admin.authority.model.MenuItem;
import com.kun.admin.authority.service.AuthorityMenuService;
import com.kun.base.web.model.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by likun on 2017/1/13.
 *
 * 管理菜单和资源链接
 */
@Controller
@RequestMapping("/admin/menu")
public class AdminMenuController {

    private static Logger logger = LoggerFactory.getLogger(AdminMenuController.class);

    @Autowired
    private AuthorityMenuService authorityMenuService;

    @RequestMapping("/getTreeData")
    @ResponseBody
    public AjaxResult getTreeData(){
        //查询出所有的菜单目录
        MenuItem menuIten=authorityMenuService.findMenuItem();
        return new AjaxResult(true,menuIten);
    }

    /**
     * 修改菜单
     * @param menu
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/update")
    public AjaxResult update(MenuItem menu){
        boolean b=authorityMenuService.update(menu);
        return new AjaxResult(b);
    }

    /**
     * 添加菜单
     * @param menu
     * @return
     */
    @RequestMapping("/create")
    @ResponseBody
    public AjaxResult create(MenuItem menu){
        boolean b=authorityMenuService.create(menu);
        return new AjaxResult(b);
    }

    /**
     * 删除菜单
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public AjaxResult delete(Long id){
        if (id==null) {
            return new AjaxResult(false);
        }
        boolean b=authorityMenuService.delete(id);
        return new AjaxResult(b);
    }

}
